﻿using System.Linq;
using Abp.Authorization;
using Abp.Localization;
using LeadThing.AbpZeroTemplate.Authorization;


namespace LeadThing.AbpZeroTemplate.VideoReceiverses.Authorization
{
    /// <summary>
    /// 权限配置都在这里。
    /// 给权限默认设置服务
    /// See <see cref="VideoReceiversAppPermissions"/> for all permission names.
    /// </summary>
    public class VideoReceiversAppAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            //在这里配置了VideoReceivers 的权限。
            var pages = context.GetPermissionOrNull(AppPermissions.Pages) ?? context.CreatePermission(AppPermissions.Pages, L("Pages"));

            var entityNameModel = pages.Children.FirstOrDefault(p => p.Name == AppPermissions.Pages_XueLiangGongCheng)
              ?? pages.CreateChildPermission(AppPermissions.Pages_XueLiangGongCheng, L("Pages_XueLiangGongCheng"));





            var videoReceivers = entityNameModel.CreateChildPermission(VideoReceiversAppPermissions.VideoReceivers, L("VideoReceivers"));
            videoReceivers.CreateChildPermission(VideoReceiversAppPermissions.VideoReceivers_CreateVideoReceivers, L("CreateVideoReceivers"));
            videoReceivers.CreateChildPermission(VideoReceiversAppPermissions.VideoReceivers_EditVideoReceivers, L("EditVideoReceivers"));
            videoReceivers.CreateChildPermission(VideoReceiversAppPermissions.VideoReceivers_DeleteVideoReceivers, L("DeleteVideoReceivers"));

        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, AbpZeroTemplateConsts.LocalizationSourceName);
        }
    }
}